<html>
<head>
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
   <script type="text/javascript" src="http://localhost:8080/KiWi2/admin/js/jquery-ui-1.8.9.custom/js/jquery-ui-1.8.9.custom.min.js"></script>
   <script type="text/javascript" src="http://coffeescripter.com/code/editable-select/jquery.editable-select.js"></script>
   <link rel="stylesheet" type="text/css" href="http://coffeescripter.com/code/editable-select/jquery.editable-select.css">
   <script type="text/javascript">

       function Frame() {

           var getUrlVars = function() {
               var vars = [], hash;
               var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
               for (var i = 0; i < hashes.length; i++) {
                   hash = hashes[i].split('=');
                   vars.push(hash[0]);
                   vars[hash[0]] = hash[1];
               }
               return vars;
           };

           var getUrlVar = function(name) {
               return getUrlVars()[name];
           };

           var url = decodeURIComponent(getUrlVar("url"));
           var data = undefined;
           this.getURL = function() {
               return url;
           };
           this.getData = function() {
               if(data==undefined) {
                    data = $("#selection").html();
                    data = data.substring(4,data.length-3);
                    data = decodeURI(data);
               }
               return data;
           };

           this.run = function() {
                if($("#start").text()=="false")
                    setTimeout(( function(obj){ return function(){ obj.run(); } } )(this),1000);
                    else $("#widget").show("scale",{},300,function(){
                    $("#widget_content").show();
                });
           };
       }

      var frame;
      $(document).ready(function(){
            frame = new Frame();
            frame.run();
            //insert stuff to run here
      });

      function showSelection() {
          alert(frame.getData())
      }
      function showParentUrl() {
          alert(frame.getURL());
      }
   </script>
</head>
<body style="margin:0;padding:0;">
<div id="selection" style="display:none;"></div>
<div id="start" style="display:none;">false</div>
<div id="widget" style="width:200px;height:200px;background-color:white;display:none;box-shadow:0 0 10px black;margin:10px;padding:10px;width:450px;height:350px;">
    <div id="widget_content" style="display:none">

        <!-- insert stuff to show here -->

        <!-- test -->
        <button onclick="showSelection()">show selection</button>
        <button onclick="showParentUrl()">show parent url</button>
    </div>
</div>
</body>
</html>